package org.easyx.ui.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.easyx.core.utils.PropertiesUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 * 系统配置加载监听器，随系统启动而启动
 */
public class SystemListener implements ServletContextListener {
	private Logger log = LoggerFactory.getLogger(SystemListener.class);
	public void contextDestroyed(ServletContextEvent arg0) {
		log.info("项目停止...");
	}

	public void contextInitialized(ServletContextEvent arg0) {
		try {
			long t1 = System.nanoTime();
			//加载系统配置
			PropertiesUtil.init();
			//加载系统前端缓存
			
			//加载系统后台缓存
			
			
			/** 获取相关的bean，并加载对应的配置*/
			WebApplicationContext app = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
			log.info("系统初始化完成，耗时["+(System.nanoTime()-t1)+"]纳秒(1秒=1000毫秒；1毫秒=1000微秒；1微秒=1000纳秒)");
		} catch (Throwable e) {
			log.error("系统初始化失败："+e.getMessage());
		}
	}

}